home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / update.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  17KB  |  633 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; update.c : parameter updating
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <string.h>
  22. #include <gemfast.h>
  23. #include "gm/gem_man.h"
  24. #include "eked-m1.h"
  25. #include "defs.h"
  26. #include "types.h"
  27. #include "externs.h"
  28.  
  29. static void snum3_update(OBJECT *object, int value);
  30. static void bit_update(OBJECT *object, int value);
  31. static void tri_update(OBJECT *object, int value);
  32. static void oct_update(OBJECT *object, int value);
  33. static void omod_update(OBJECT *object, int value);
  34. static void amod_update(OBJECT *object, int value);
  35. static void note_update(OBJECT *object, int value);
  36. static void key_update(OBJECT *object, int value);
  37. static void msnd_update(OBJECT *object, int value);
  38. static void dsnd_update(OBJECT *object, int value);
  39. static void rev_update(OBJECT *object, int value);
  40. static void ert_update(OBJECT *object, int value);
  41. static void del_update(OBJECT *object, int value);
  42. static void sped_update(OBJECT *object, int value);
  43. static void bal_update(OBJECT *object, int value);
  44. static void pan_update(OBJECT *object, int value);
  45. static void lfc_update(OBJECT *object, int value);
  46. static void hfc_update(OBJECT *object, int value);
  47. static void twav_update(OBJECT *object, int value);
  48. static void rout_update(OBJECT *object, int value);
  49. static void vel_update(OBJECT *object, int value);
  50. static void dis_update(OBJECT *object, int value);
  51. static void chan_update(OBJECT *object, int value);
  52. static void cpan_update(OBJECT *object, int value);
  53. static void pol_update(OBJECT *object, int value);
  54. static void ped_update(OBJECT *object, int value);
  55. static void scal_update(OBJECT *object, int value);
  56.  
  57. typedef struct {
  58.   int min;            /* minimum value */
  59.   int max;            /* maximum value */
  60.   UPDATE_FUNC_PTR update;    /* update function */
  61. } PARA_ATRB;
  62.  
  63. PARA_ATRB atrb_table[] = {
  64.   {0,    99,    &unum_update},        /* UNUM */
  65.   {0,    3,    &unum1_update},        /* UN3 */
  66.   {-99,    99,    &snum_update},        /* SNUM */
  67.   {-12,    12,    &snum_update},        /* SN12 */
  68.   {-50,    50,    &snum_update},        /* SN50 */
  69.   {0,    99,    &msnd_update},        /* MSND */
  70.   {-1,    1,    &oct_update},        /* OCT */
  71.   {0,    127,    ¬e_update},        /* NOTE */
  72.   {0,    2,    &omod_update},        /* OMOD */
  73.   {0,    1,    &pol_update},        /* POL */
  74.   {0,    9,    &ped_update},        /* PED */
  75.   {0,    4,    &scal_update},        /* SCAL */
  76.   {0,    11,    &key_update},        /* KEY */
  77.   {0,    44,    &dsnd_update},        /* DSND */
  78.   {12,    115,    ¬e_update},        /* DKEY */
  79.   {-120,120,    &snum3_update},        /* S120 */
  80.   {1,    127,    &vel_update},        /* VEL */
  81.   {0,    97,    &rev_update},        /* REV1 */
  82.   {0,    47,    &rev_update},        /* REV2 */
  83.   {0,    70,    &ert_update},        /* ERT1 */
  84.   {0,    30,    &ert_update},        /* ERT2 */
  85.   {0,    9,    &unum1_update},        /* UN9 */
  86.   {-10,    10,    &snum_update},        /* SN10 */
  87.   {0,    100,    &bal_update},        /* BAL */
  88.   {0,    101,    &pan_update},        /* PAN */
  89.   {0,    2,    &lfc_update},        /* LFC */
  90.   {0,    2,    &hfc_update},        /* HFC */
  91.   {0,    50,    &del_update},        /* DEL1 */
  92.   {0,    150,    &del_update},        /* DEL2 */
  93.   {0,    200,    &del_update},        /* DEL3 */
  94.   {0,    216,    &sped_update}        /* SPED */
  95. };
  96.  
  97. void para_edit(int handle, OBJECT *tree, int ob,
  98.                PARA_TYPE t, int page, int pos, BYTE *data)
  99. {
  100.   int new, old, d;
  101.   char *s;
  102.  
  103.   switch(t){
  104.   case UNUM: case UN3:  case SNUM: case SN12:
  105.   case SN50: case MSND: case OCT:  case NOTE:
  106.   case OMOD: case POL:  case PED:  case SCAL:
  107.   case KEY:  case DSND: case DKEY: case S120:
  108.   case VEL:
  109.   case REV1: case REV2: case ERT1: case ERT2:
  110.   case UN9:  case SN10: case BAL:  case PAN:
  111.   case LFC:  case HFC:  case DEL1:
  112.   case DEL2: case DEL3: case SPED:
  113.     old = (t >= DEL2) ? ((UBYTE) *data) : *data;
  114.     new = wm_roll(handle, tree, ob, old, atrb_table[t].min, atrb_table[t].max,
  115.                   atrb_table[t].update);
  116.     if(new != old){
  117.       *data = new;
  118.       tx_para_chg(page, pos, new);
  119.     }
  120.     break;
  121.   case PROG:
  122.     old = (data[10] & 0x10) ? -1 : (data[0] & 0xFF);
  123.     new = wm_roll(handle, tree, ob, old, -1, 199, &prog_update);
  124.     if(new != old){
  125.       if(new == -1)
  126.         data[10] |= 0x10;
  127.       else{
  128.         data[10] &= ~0x10;
  129.         data[0] = new;
  130.       }
  131.       tx_para_chg(page, pos, new + 1);
  132.     }
  133.     break;
  134.   case WAVE:
  135.     old = EXTRACT_2LO(*data);
  136.     new = wm_roll(handle, tree, ob, old, 0, 3, &wave_update);
  137.     if(new != old){
  138.       *data = REPLACE_2LO(*data, new);
  139.       tx_para_chg(page, pos, new);
  140.     }
  141.     break;
  142.   case AMOD:
  143.     old = EXTRACT_BIT(*data, 0);
  144.     new = wm_roll(handle, tree, ob, old, 0, 1, &amod_update);
  145.     if(new != old){
  146.       *data = REPLACE_BIT(*data, 0, new);
  147.       tx_para_chg(page, pos, new);
  148.     }
  149.     break;
  150.   case BIT0: case BIT1: case BIT2: case BIT3:
  151.   case BIT4: case BIT5: case BIT6: case BIT7:
  152.     t -= BIT0;
  153.     d = *data;
  154.     old = EXTRACT_BIT(d, t);
  155.     new = wm_roll(handle, tree, ob,  old, 0, 1, &bit_update);
  156.     if(new != old){
  157.       *data = REPLACE_BIT(d, t, new);
  158.       if(t == 5 || t == 6) /* modulation bits have to be changed together */
  159.         tx_para_chg(page, pos, EXTRACT_56(*data));
  160.       else
  161.         tx_para_chg(page, pos, new);
  162.     }
  163.     break;
  164.   case TRI0: case TRI1: case TRI2: case TRI3:
  165.     t -= TRI0;
  166.     d = *data;
  167.     old = EXTRACT_BIT(d, t) ? (EXTRACT_BIT(d, t + 4) ? -1 : 1) : 0;
  168.     new = wm_roll(handle, tree, ob, old, -1, 1, &tri_update);
  169.     if(new != old){
  170.       d = REPLACE_BIT(d, t, new != 0);
  171.       *data = REPLACE_BIT(d, t + 4, new < 0);
  172.       tx_para_chg(page, pos, new + 1);
  173.     }
  174.     break;
  175.   case NM10:
  176.     tree[ob].ob_state |= SELECTED;
  177.     wm_ob_update(handle, tree, ob);
  178.     s = TEXT_PTR(name_form, NM_NAME);
  179.     (void) korg2str(s, data, (size_t) 10);
  180.     d = fm_dialog(name_form, NM_NAME, tree, ob);
  181.     if(d == NM_OK){
  182.       (void) str2korg(data, s, (size_t) 10);
  183.       (void) strfcpy(TEXT_PTR(tree, ob), s, (size_t) 10);
  184.     }
  185.     tree[ob].ob_state &= ~SELECTED;
  186.     wm_ob_update(handle, tree, ob);
  187.     break;
  188.   case TWAV:
  189.     d = *data;
  190.     old = EXTRACT_BIT(d, 0);
  191.     new = wm_roll(handle, tree, ob,  old, 0, 1, &twav_update);
  192.     if(new != old){
  193.       *data = REPLACE_BIT(d, 0, new);
  194.       tx_para_chg(page, pos, new);
  195.     }
  196.     break;
  197.   case DEL4:
  198.     old = ((UBYTE) (data[0])) + (((UBYTE) (data[1])) << 8);
  199.     new = wm_roll(handle, tree, ob,  old, 0, 500, &del_update);
  200.     if(new != old){
  201.       data[0] = new;
  202.       data[1] = new >> 8;
  203.       tx_para_chg(page, pos, new);
  204.     }
  205.     break;
  206.   case ROUT:
  207.     d = *data;
  208.     old = EXTRACT_BIT(d, 4);
  209.     new = wm_roll(handle, tree, ob,  old, 0, 1, &rout_update);
  210.     if(new != old){
  211.       *data = REPLACE_BIT(d, 4, new);
  212.       tx_para_chg(page, pos, new);
  213.     }
  214.     break;
  215.   case DIS0: case DIS1: case DIS2: case DIS3:
  216.     t -= DIS0;
  217.     d = *data;
  218.     old = EXTRACT_BIT(d, t);
  219.     new = wm_roll(handle, tree, ob,  old, 0, 1, &dis_update);
  220.     if(new != old){
  221.       *data = REPLACE_BIT(d, t, new);
  222.       tx_para_chg(page, pos, new);
  223.     }
  224.     break;
  225.   case CHAN:
  226.     d = *data;
  227.     old = EXTRACT_NYBLE(d);
  228.     new = wm_roll(handle, tree, ob,  old, 0, 15, &chan_update);
  229.     if(new != old){
  230.       *data = REPLACE_NYBLE(d, new);
  231.       tx_para_chg(page, pos, new);
  232.     }
  233.     break;
  234.   case CPAN:
  235.     d = *data;
  236.     old = EXTRACT_NYBLE(d);
  237.     new = wm_roll(handle, tree, ob,  old, 0, 13, &cpan_update);
  238.     if(new != old){
  239.       *data = REPLACE_NYBLE(d, new);
  240.       tx_para_chg(page, pos, new);
  241.     }
  242.